import keycloak from './keycloak'
import { createApp } from 'vue'

const KeycloakPlugin = {
  install(app) {
    keycloak.init({ onLoad: 'check-sso', checkLoginIframe: false })
      .then((authenticated) => {
        if (authenticated) {
          app.provide('keycloak', keycloak)
        }
        else {
          console.warn('User not authenticated')
        }
      })
      .catch((err) => {
        console.error('Failed to initialize Keycloak', err)
      })
  },
}

export default KeycloakPlugin
